package com.gem.service.impl;

import com.gem.entity.Student;
import com.gem.mapper.StudentMapper;
import com.gem.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘聪
 * Created  on 2020/10/9
 */
@Service
public class StudentServiceImpl implements StudentService {


    @Autowired
    StudentMapper studentMapper;

    @Override
    public Student login(String name, String password) {
        return studentMapper.login(name, password);
    }

    @Override
    public void addStudent(Student student) {
        studentMapper.addStudent(student);
    }

    @Override
    public void deleteStudents(Long id) {
        studentMapper.delete(id);
    }

    @Override
    public void editStudents(Student student) {
        studentMapper.editStudent(student);
    }

    @Override
    public List<Student> searchAllStudents() {
        return studentMapper.selectAllStudent();
    }

    @Override
    public Student searchStudentByNumber(String studentNumber) {
        return studentMapper.searchStudentByNumber(studentNumber);
    }

    @Override
    public Student searchStudentById(Long id) {
        return studentMapper.searchStudentById(id);
    }

    @Override
    public PageInfo<Student> searchByNamePages(Integer pageNum, Integer pageSize,String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> students = studentMapper.selectByName(name);
        return new PageInfo<Student>(students);
    }


    @Override
    public PageInfo<Student> listPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> students = studentMapper.selectAllStudent();
        return new PageInfo<Student>(students);
    }
}
